<?php TPL::output('m/header_meta.tpl.htm'); ?>
    <div class="searchbox" style="padding: 5px 12px;">
        <form id="search_form" action="m/search/" method="post">
            <div class="searchinfo w_box">
                <input name="q" placeholder="搜索" type="text">
            </div>
        </form>
    </div>
<!--tab-->
<div class="phb_two">
    <a class="tab <?php if (!$this->user_id) { ?>cur<?php } ?>" type="all">全部话题</a>
      <?php if ($this->user_id) { ?>
    <a  class=" tab" type="focus">已关注话题</a>
         <?php } ?>
</div>
<!--tab end-->
<!--关注列表-->
<div class="nlists ">
</div>
<div class="flow-default follow" id="demo">
</div>
<!--推荐列表end-->
    <script type="text/javascript">
   $(document).ready(function() {
         $(document).on('click','.follow>h3', function (k) {
            if($(this).hasClass('current')){
                $(this).removeClass('current');
                $(this).parent().find('dl').hide();
                $(this).find('.showdown').html('<img src="/static/mobile/images/open_ico.png">展开');
            }else{
                $(this).addClass('current');
                $(this).find('.showdown').html('<img src="/static/mobile/images/sq.png">收起');
                $(this).parent().find('dl').show();
            }
         });
        $(document).on('click','.d_right a',function(){
            var topic_id=$(this).attr('topic_id');
            var type=$(this).attr('type');
             var uid = "<?php echo $this->user_id;?>";
                    if(uid){
                        if(topic_id)
                      AWS.User.follow($(this), 'topic',topic_id,'<?php echo new_post_hash();?>');
                    }else{
                     setTimeout(AWS.DingTalk.showToast('', '请先登录'), 500);
                     window.location = "?/m/login/";
                    }
        });  
    });     
    </script>
      <link rel="stylesheet" href="/static/mobile/layui/css/layui.css"  media="all">
    <script src="/static/mobile/layui/layui.js"></script>
    <script type="text/javascript">
            layui.use('flow', function(){
              var $ = layui.jquery; 
              var flow = layui.flow;
            $(".tab").each(function (i) {
                $(this).on('click', function (k) {
                    var type=$(this).attr('type');
                    $(this).addClass('cur').siblings().removeClass('cur');
                    var uid = "<?php echo $this->user_id;?>";
                    var keyword="<?php echo $this->keyword;?>";
                    if (type == 'focus'){
                                $(".nlists").hide();
                                $("#demo").show();

                        var url = G_BASE_URL + '/m/ajax/search_focus_topics/';
                          flow.load({
                            elem: '#demo',
                            end:'SORRY~!没有了'
                            ,done: function(page, next){ 
                              var lis = [];
                              var page=page-1;
                              $.get(url+'?page='+page, function(res){
                                // console.log(res.code);
                                     if(res.pages){
                                 var id=$(".nlists").find('.follow'); 
                                 if(id){
                                    id.remove();
                                 } 
                                 if(eval(res.data).length<1){
                                    AWS.DingTalk.showToast('', '暂无更多内容');
                                 }
                                 var html='';
                            
                                layui.each(res.data, function(index, item){
                                    html+='<dl><dt><img src="'+item.topic_pic+'"></dt>'+
                                            '<a href="topic/'+item.topic_id+'"><dd class="d_center">'+
                                            '<h4>'+item.topic_title+'</h4>'+
                                            '<p><span>'+item.focus_count+'人关注</span></p>'+
                                            '</dd></a><dd class="d_right"><a type="off" class="active">√ 已关注</a></dd>'+
                                            '<div class="clear"></div></dl>';
                                }); 
                                  lis.push(html);
                                 next(lis.join(''), page < res.pages);  
                                 }else{
                                    $('.layui-flow-more').remove();
                                    $('.flow-default').append('<div class="mod-body"><ul id="best_answers_listview"><p style="padding: 15px 0" align="center">没有内容</p></ul></div>');
                                 }

                              },'json');
                            }
                          });
                    }else{
                        var url = G_BASE_URL + '/m/ajax/search_hot_topics/';
                        $.ajax({
                            url: url,
                            type: 'GET',
                            data: {search_type: type, keyword: keyword},
                            success: function (data) {
                                $("#demo").hide();
                                $(".nlists").show();
                                $(".nlists").empty().append(data);
                            }
                        })  
                    }


                })
            });
            $(".tab").eq(0).click();
            });
    </script>
<?php TPL::output('m/footer.tpl.htm'); ?>


